import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)




const routes = [
  {
    path: '/',
    name: 'login', //登录界面
    component: () => import('@/components/common/login')
  },
  {
    path: '/index', //教师主页
    component: () => import('@/components/admin/index'),
    children: [
      {
        path: '/', //首页默认路由
        component: () => import('@/components/teacher/hello')
      },
      {
        path: '/grade', //学生成绩
        component: () => import('@/components/charts/grade')
      },
      {
        path: '/selectExamToPart', //学生分数段
        component: () => import('@/components/teacher/selectExamToPart')
      },
      {
        path: '/adminselectExamToPart', //学生分数段
        component: () => import('@/components/admin/selectExamToPart')
      },
      {
        path: '/scorePart',//老师查看分段
        component: () => import('@/components/charts/scorePart')
      },
      {
        path: '/allStudentsGrade', //所有学生成绩统计
        component: () => import('@/components/teacher/allStudentsGrade')
      },
      {
        path: '/examDescription', //考试管理功能描述
        component: () => import('@/components/teacher/examDescription')
      },
      {
        path: '/selectExam', //查询所有考试
        component: () => import('@/components/teacher/selectExam')
      },
      {
        path: '/addExam', //添加考试
        component: () => import('@/components/teacher/addExam')
      },
      {
        path: '/answerDescription', //题库管理功能介绍
        component: () => import('@/components/teacher/answerDescription')
      },
      {
        path: '/selectAnswer', //查询所有题库
        component: () => import('@/components/teacher/selectAnswer')
      },
      {
        path: '/addAnswer', //增加题库主界面
        component: () => import('@/components/teacher/addAnswer')
      },
      {
        path: '/addAnswerChildren', //点击试卷跳转到添加题库页面
        component: () => import('@/components/teacher/addAnswerChildren')
      },
      {
        path: '/studentManage', //学生管理界面
        component: () => import('@/components/teacher/studentManage')
      },
      {
        path: '/addStudent', //添加学生
        component: () => import('@/components/teacher/addStudent')
      },
      {
        path: '/adminstudentManage', //学生管理界面
        component: () => import('@/components/admin/studentManage')
      },
      {
        path: '/adminaddStudent', //添加学生
        component: () => import('@/components/admin/addStudent')
      },
      {
        path: '/teacherManage',//管理员查询教师
        component: () => import('@/components/admin/tacherManage')
      },
      {
        path: '/addTeacher',
        component: () => import('@/components/admin/addTeacher')
      },
      {
        path: '/tongaoManage',
        component: () => import('@/components/admin/tongaoManage')
      },
      {
        path: '/addTongzhi',
        component: () => import('@/components/admin/addTongzhi')
      },
      {
        path: '/shenheManage',//审核考试
        component: () => import('@/components/admin/shenheManage')
      },
      {
        path: '/admingrade', //管理员查看学生成绩
        component: () => import('@/components/charts/admingrade')
      },
      {
        path: '/adminselectExamToPart', //学生分数段
        component: () => import('@/components/admin/selectExamToPart')
      },
      {
        path: '/adminscorePart',  //管理员查看分段
        component: () => import('@/components/charts/adminscorePart')
      },
      {
        path: '/adminallStudentsGrade', //管理员所有学生成绩统计
        component: () => import('@/components/admin/allStudentsGrade')
      },
      {
        path: '/adminselectAnswer', //管理员查询所有题库
        component: () => import('@/components/admin/selectAnswer')
      },
      {
        path: '/tongaoManage',
        component: () => import('@/components/admin/tongaoManage')
      },
      {
        path: '/addTongzhi',
        component: () => import('@/components/admin/addTongzhi')
      },
      {
        path: '/adminstudentManage', //学生管理界面
        component: () => import('@/components/admin/studentManage')
      },
      {
        path: '/adminaddStudent', //添加学生
        component: () => import('@/components/admin/addStudent')
      },
      {
        path: '/allStudentsGradeshenhe',//审核成绩
        component: () => import('@/components/admin/allStudentsGradeshenhe')
      }
    ]
  },
  {
    path: '/student',
    component: () => import('@/components/student/index'),
    children: [
      { path: "/", component: () => import('@/components/student/myExam') },
      { path: '/startExam', component: () => import('@/components/student/startExam') },
      { path: '/manager', component: () => import('@/components/student/manager') },
      { path: '/examMsg', component: () => import('@/components/student/examMsg') },
      { path: '/message', component: () => import('@/components/student/message') },
      { path: '/studentScore', component: () => import("@/components/student/answerScore") },
      { path: '/scoreTable', component: () => import("@/components/student/scoreTable") }
    ]
  },
  { path: '/answer', component: () => import('@/components/student/answer') }
]


const router = new Router({

  routes
  
});


router.beforeEach((to,from,next)=>{
  if(to.path=='/'){
    next();
  }else{
    let token =  localStorage.getItem("token");
    let role = localStorage.getItem("role")
    if(token==null || token == ''){
      alert("您还没有登录,请您先登录")

      next('/')
    }else{
      next()
    }
  }
})






export default router